package logic

import (
	"context"
	"house_srv/models"

	"house_srv/home"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HomeShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHomeShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HomeShowLogic {
	return &HomeShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HomeShowLogic) HomeShow(in *home.HomeShowRequest) (*home.HomeShowResponse, error) {
	var h models.Home
	h.ID = uint(in.HomeId)
	err := h.HomeShow()
	if err != nil {
		logx.Error("房源详情展示失败", err)
		return nil, err
	}

	return &home.HomeShowResponse{
		Title:   h.Title,
		Address: h.Address,
		Num:     int64(h.Num),
		Price:   float32(h.Price),
	}, nil
}
